let loginBtns = document.querySelectorAll(".login a")
let loginDiv  = document.querySelectorAll(".login-box .login-div")
loginBtns.forEach(function(v,i){
    v.addEventListener("click",function(){
        for(let x=0;x<loginBtns.length;x++){
            loginBtns[x].className=""
            loginDiv[x].classList.remove("login-active")
        }
        this.className = "active"
        loginDiv[i].classList.add("login-active")
    })
})


let username = document.querySelector("input[placeholder='用户名/手机号/邮箱']")
let password = document.querySelector("input[placeholder='密码']")
let btn = document.querySelector("button")
let noUserName = document.querySelector(".no-username")
let noPassword = document.querySelector(".no-password")
let loginSuccess = document.querySelector(".login-success")
btn.addEventListener("click",function(){
    if(username.value.length<6||username.value.length>12){
        noUserName.style.display = "block"
        let t = setTimeout(function(){
            noUserName.style.display = "none"
        },1000)
    }else if(password.value.length<6||password.value.length>12) {
        noPassword.style.display = "block"
        let t = setTimeout(function(){
            noPassword.style.display = "none"
        },1000)
    }else{
        loginSuccess.style.display = "block"
        let t = setTimeout(function(){
            loginSuccess.style.display = "none"
            location.href="index.html"
        },3000)

    }
})



let cancleUserName = document.querySelector(".login-username img")
let canclePassword = document.querySelector(".login-password img")
let eye = document.querySelector(".eye")
username.addEventListener("input",function(){
    if(username.value === ""){
        cancleUserName.style.display = "none"
    }else{
        cancleUserName.style.display = "block"
    }
})
password.addEventListener("input",function(){
    if(username.value === ""){
        canclePassword.style.display = "none"
    }else{
        canclePassword.style.display = "block"
    }
})
cancleUserName.addEventListener("click",function(){
    username.value = ""
})
canclePassword.addEventListener("click",function(){
    password.value = ""
})
password.addEventListener("input",function(){
    if(password.value.length>0){
        eye.style.display = "block"
    }else{
        eye.style.display = "none"
    }
})
eye.addEventListener("click",function(){
    if(password.type==="password"){
        password.type = "text"
        eye.style.backgroundImage = "url(../imgs/close-eye.png)"
    }// }else{
    //     password.type = "password"
    //     eye.style.backgroundImage = "url(../imgs/eye.png)"
    // }
})